package servlet.dispatch;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import member.domain.Member;

public class MakeErrorServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// application scope에서 admin이름으로 binding된 속성 조회.
		ServletContext ctx = getServletContext();
		Member admin = (Member) ctx.getAttribute("admin");
		System.out.println("MakeErrorServlet : admin : " + admin);
		
		String url = null;
		try {
			int i = 10 / 0;
			url = "성공페이지 url";
		} catch (Exception e) {
			e.printStackTrace();
			url = "/dispatch/error.jsp";// /위치: application root directoty
										// (myServlet)
			request.setAttribute("error_message", "0으로 나눌 수 없습니다.");// binding
		}
		// 요청 디스패치 방식으로 수행을 url로 이동.
		RequestDispatcher rdp = request.getRequestDispatcher(url);// 정상이라명 정상url
																	// 들어가고 오류면
																	// dispatch
																	// url들어감
		rdp.forward(request, response);// 수행을 이동시켜라!
	}

}
